<template>
  <div class="layout">
    <Topnav
      class="nav"
      toggleMenuButtonVisible
      :menuVisible="menuVisible"
      @clickEvent="menuVisible=!menuVisible"
    />
    <div class="content">
      <aside v-if="menuVisible">
        <h2>文档</h2>
        <ol>
          <li>
            <router-link to="/doc/intro">介绍</router-link>
          </li>
          <li>
            <router-link to="/doc/install">安装</router-link>
          </li>
          <li>
            <router-link to="/doc/get-started">开始使用</router-link>
          </li>
        </ol>
        <h2>组件列表</h2>
        <ol>
          <li>
            <router-link to="/doc/switch">Switch 组件</router-link>
          </li>
          <li>
            <router-link to="/doc/button">Button 组件</router-link>
          </li>
          <li>
            <router-link to="/doc/dialog">Dialog 组件</router-link>
          </li>
          <li>
            <router-link to="/doc/tabs">Tabs 组件</router-link>
          </li>
        </ol>
      </aside>
      <main>
        <router-view />
      </main>
    </div>
  </div>
</template>

<script>
import Topnav from '../components/Topnav.vue'
import router from '../router/index.js'
export default {
  data() {
    const width = document.documentElement.clientWidth
    const menuVisible = width > 500
    return {
      menuVisible: menuVisible
    }
  },
  created() {
    router.afterEach(() => {
      // console.log('路由切换了')
      if (document.documentElement.clientWidth <= 500) {
        this.menuVisible = false
      }
    })
  },
  components: { Topnav }
}
</script>

<style lang="scss" scoped>
.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  > .nav {
    flex-shrink: 0;
  }
  > .content {
    flex-grow: 1;
    padding-top: 60px;
    padding-left: 156px;
    @media (max-width: 500px) {
      padding-left: 0;
    }
  }
}
.content {
  display: flex;
  > aside {
    flex-shrink: 0;
  }
  > main {
    flex-grow: 1;
    padding: 16px;
    background: white;
  }
}
aside {
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.25);
  width: 150px;
  padding: 16px 0;
  position: fixed;
  top: 0;
  left: 0;
  padding-top: 70px;
  height: 100%;
  > h2 {
    padding: 0 16px;
    margin: 10px 0;
  }
  > ol {
    > li {
      padding: 5px 0;
      > a {
        display: block;
        padding: 10px 16px;
        text-decoration: none;
      }
      .router-link-active {
        // color: #40a9ff;
        color: #0fc0b9;
        // background: #e6f7ff;
        background: #e1fefc;
        text-decoration: none;
        border-right: 3px solid #0fc0b9;
      }
    }
  }
}
main {
  overflow: auto;
}
@media (max-width: 500px) {
  aside {
    background: white;
    z-index: 5;
  }
}
</style>
